﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Commander.Common.DataContracts;
using SKit.Databases.NHibernate.Repositories;
using SKit.Databases;
using Commander.DataLayer.Entities;

namespace Commander.DataLayer.Services.Implementations {
	public class SmellService: ISmellService {
		static DomainRepository<Smell> m_smellRepo;
		static DomainRepository<Smell> Repo {
			get {
				if (m_smellRepo == null) {
					m_smellRepo = new DomainRepository<Smell>();
				}
				return m_smellRepo;
			}
		}

		public RefactoringMessage GetRefactoringApproach(SmellMessage smell) {
			var smelly = m_smellRepo.RetrieveEntities(e => e.Name.Equals(smell.Name)).Single();
			return new RefactoringMessage { Approach = smelly.Recommended.Approach, Name = smelly.Recommended.Name };
		}

		public ExplanationMessage GetExplanation(SmellMessage smell) {
			var smelly = m_smellRepo.RetrieveEntities(e => e.Name.Equals(smell.Name)).Single();
			return new ExplanationMessage { Content = smelly.Reason.Content };
				
		}
	}
}
